package cn.range.utils;

import java.sql.Connection;
import java.sql.DriverManager;
import java.sql.PreparedStatement;
import java.sql.ResultSet;
import java.sql.SQLException;

import cn.range.domain.DefinedConstants;

public class DBQueryAllResults {
	private static DefinedConstants dc = new DefinedConstants();
	
	public static DefinedConstants getDc() {
		return dc;
	}
	
	/**
	 * Get all results in Database
	 * @param sel 0 for suctable, 1 for fiptable, 2 for bgsmstable,
	 * 			other will get no result
	 * @return rs
	 * @throws ClassNotFoundException
	 * @throws SQLException
	 */
	public static ResultSet queryDB(int sel) 
			throws ClassNotFoundException, SQLException{
		Class.forName(getDc().getDbDriverName());
		Connection conn = DriverManager.getConnection(getDc().getDbConnName(), 
				getDc().getDbUserName(), getDc().getDbPwd());
		PreparedStatement pStmt;
		ResultSet rs;
		switch(sel){
		case 0:
			pStmt = conn.prepareStatement(getDc().getDbQueryStrSuctable());
			rs = pStmt.executeQuery();
			return rs;
		case 1:
			pStmt = conn.prepareStatement(getDc().getDbQueryStrFiptable());
			rs = pStmt.executeQuery();
			return rs;
		case 2:
			pStmt = conn.prepareStatement(getDc().getDbQueryStrBgsmstable());
			rs = pStmt.executeQuery();
			return rs;
		default:
			return null;
		}
	}
}
